package com.zcwin.runner.sms.bean;

import java.util.HashMap;
import java.util.Map;

import com.zcwin.runner.utils.ConfigManager;

/**
 *
 * 获取短信配置
 * @author wsjjiang
 * @version 1.0
 */
public class SmsConfig
{
    private static SmsServerConfig smsConfig = null;
    private static Map<String,String> sendMsg;
    private static Map<String,String> resultMsg;
    public synchronized static SmsServerConfig getConfig()
    {
        if(smsConfig == null)
        {
            smsConfig = new SmsServerConfig();
            smsConfig.setUrl(ConfigManager.getInstance().getConfigItem("sms.url","").toString());
            try {
                smsConfig.setLength(Integer.parseInt(ConfigManager.getInstance().getConfigItem("sms.length","250").toString()));
            } catch (Exception e) {
                smsConfig.setLength(300);
            }
            try {
                smsConfig.setRetry(Integer.parseInt(ConfigManager.getInstance().getConfigItem("sms.retry","3").toString()));
            } catch (Exception e) {
                smsConfig.setRetry(2);
            }
            try {
                smsConfig.setSmsclcount(Integer.parseInt(ConfigManager.getInstance().getConfigItem("sms.smsclcount","10").toString()));
            } catch (Exception e) {
                smsConfig.setSmsclcount(10);
            }
            try {
                smsConfig.setSmscallback(Integer.parseInt(ConfigManager.getInstance().getConfigItem("sms.smscallback","2").toString()));
            } catch (Exception e) {
                smsConfig.setSmscallback(2);
            }
            try {
            	smsConfig.setTxinterval(Integer.parseInt(ConfigManager.getInstance().getConfigItem("sms.txinterval","5").toString()));
            } catch (Exception e) {
            	smsConfig.setTxinterval(5);
            }
        }
        return smsConfig;
    }

    public static String getSendMsg(String code)
    {
        if(sendMsg.containsKey("key"+code))
        {
            return sendMsg.get("key"+code);
        }
        return "未知状态";
    }
    public static String getResultMsg(String code)
    {
        if(resultMsg.containsKey("key"+code))
        {
            return resultMsg.get("key"+code);
        }
        return "未知状态";
    }


    static
    {
        sendMsg = new HashMap<String,String>();
        sendMsg.put("key-1", "");
        sendMsg.put("key1", "发送成功");
        sendMsg.put("key0", "发送失败");

        resultMsg = new HashMap<>();
        resultMsg.put("key1","成功");
        resultMsg.put("key-1","用户名或密码错误");
        resultMsg.put("key-2","没有可取数据");
        resultMsg.put("key-3","异常情况");
        resultMsg.put("key-4","tkey不正确");
    }
}
